#include <stdio.h>
#include <set>
#include <map>

enum ListenEvent {
    Event_New = 1,
};

class Listener {
public:
    virtual ~Listener() = default;
    virtual void onNotify(ListenEvent event, const char *param) {}
    //virtual void onNotify(ListenEvent event, void *param) {}
};

typedef std::set<Listener *> ListenerSet;
typedef std::map<ListenEvent, ListenerSet> ListenerMap;

class Notify {
public:
    virtual ~Notify() = default;
    virtual void addListener(ListenEvent event, Listener *listenner) {
        m_listenners[event].insert(listenner);
    }

    virtual void removeListener(ListenEvent event, Listener *listenner) {
        auto it = m_listenners.find(event);
        if (it == m_listenners.end()) return;

        it->second.erase(listenner);
    }

    virtual void clearListener() { this->m_listenners.clear(); }

    virtual void onNotify(ListenEvent event, const char *param) {
        auto it = this->m_listenners.find(event);
        if (it == this->m_listenners.end())  return;

        for (const auto& sit : it->second) {
            sit->onNotify(event, param);
        }
    }

private:
    ListenerMap m_listenners;
};

class New : public Listener {
public:
    void onNotify(ListenEvent event, const char *param) override {
        printf("eventId: %d, %s\n", event, param);
    }
};

class Worker : public Notify {

};

int main(int argc, const char **argv) {
    Worker worker;
    New xx;
    worker.addListener(Event_New, (Listener *)(&xx));
    worker.onNotify(Event_New, "hellow world");
    return 0;
}
